package com.hngy.xpq.android_handler;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    final int TIME = 100;
    final int TIME_GAS = 0x11;
    float MATH = 0;
    private ProgressBar time;
    private int mTIME = 0;
    ProgressBar progressBar;
    TextView math;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressBar = findViewById(R.id.progress);
        math = findViewById(R.id.math);

        handler.sendEmptyMessage(TIME_GAS);
    }

    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if (mTIME<TIME){
                mTIME += 1;
                MATH += 1;
                String Imath = String.valueOf(MATH) + "%";
                math.setText(Imath);
                progressBar.setProgress(mTIME);
                handler.sendEmptyMessageDelayed(TIME_GAS,10);
            } else {
                Toast.makeText(MainActivity.this,"进度完成!!",Toast.LENGTH_SHORT).show();
            }
        }
    };

}